﻿<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>IP_WFStart</title>
    <link href="../../Content/Site.css" rel="stylesheet" type="text/css" />

    <script type="text/javascript" src="<%=Url.Content("~/Scripts/jquery-1.4.1.min.js") %>"></script>

    <script type="text/javascript" src="<%=Url.Content("~/Scripts/MicrosoftAjax.js") %>"></script>

    <script type="text/javascript" src="<%=Url.Content("~/Scripts/MicrosoftMvcAjax.js") %>"></script>

    <script type="text/javascript" src="<%=Url.Content("~/Scripts/MicrosoftMvcValidation.js") %>"></script>

    <script type="text/javascript" src="<%=Url.Content("~/Scripts/AjaxLoadedContentScriptFix.js") %>"></script>

    <script type="text/javascript" src="../../Scripts/jqueryui-1.8.21/js/jquery-ui-1.8.21.custom.min.js"></script>

    <link type="text/css" href="../../Scripts/jqueryui-1.8.21/css/redmond/jquery-ui-1.8.21.custom.css"
        rel="stylesheet" />
    <!--ztree-->
    <link rel="stylesheet" href="../../Scripts/zTree/css/demo.css" type="text/css" />
    <link rel="stylesheet" href="../../Scripts/zTree/css/zTreeStyle/zTreeStyle.css" type="text/css" />

    <script type="text/javascript" src="../../Scripts/zTree/js/jquery.ztree.core-3.0.js"></script>

    <script type="text/javascript" src="../../Scripts/zTree/js/jquery.ztree.excheck-3.0.js"></script>

    <script type="text/javascript" src="../../Scripts/zTree/js/jquery.ztree.exedit-3.0.js"></script>

    <script type="text/javascript">
        $(function() {
            $(".form_datepicker").datepicker();
        })

        //统计tree上选中的人员，将其组成一个字符串数组存放在 id=selectarr 隐藏标签中
        function onUsertreeCheck_WF(event, treeId, treeNode) {
            //alert(treeNode.id + ", " + treeNode.name + "," + treeNode.checked);
            var treeObj = $.fn.zTree.getZTreeObj("treeDemo");
            var nodes = treeObj.getCheckedNodes(true);
            var temp = "";
            for (i = 0; i < nodes.length; i++) {
                temp = temp + nodes[i].id + ",";
            }
            $("#selectarr").attr("value", temp);
        };

        var complete = false;
        function getTable(btnTag) {
            var hidValue;
            var txtValue = "";
            complete = true;

            var tableTag = $(btnTag).parent();
            var childTag = $(tableTag).children();

            childTag.each(function() {
                var cls = $(this).attr("class");
                if (cls == "txtTable txtunderline") {
                    var txt = $(this).val();
                    var name = $(this).attr("name");
                    if (txt == "")
                        complete = false;
                    txtValue += txt + ";";
                }
                else if (cls == "hidTable")
                    hidValue = $(this).val();
            });

            //        if (!complete) {
            //            alert("必须填写完整条件");
            //            return;
            //        }
            //alert(txtValue);
            $.ajax({
                type: "POST",
                url: "/Form/QueryTable",
                data: { "txtValue": txtValue, "sqlValue": hidValue },
                success: function(data) {
                    if (data == "none") {
                        alert("无所需查询结果");
                        complete = false;
                    } else {
                        complete = true;
                        $("#updateTable").html(data);
                    }
                }
            });
        };

        function OnSubmit() {

            var flag, msg;
            var table = document.getElementById("updateTable");
            var tableId = $(table).attr("id");
            if (tableId == 'updateTable') {
                if (!complete) {
                    var count = $(".txtTable").length;
                    if (count == 0)
                        flag = true;
                    else
                        flag = false;
                } else {
                    flag = true;
                }
            } else {
                flag = true;
            }

            //        if ($("#wf_name").val() == "") {
            //            flag = false;
            //            msg = "请填写流程名";
            //        }
            if ($("#treevis").val() == "T") {
                if ($("#selectarr").val() == "") {
                    flag = false;
                    msg = "请选择处理人";
                }
            }
            //先取消每个input都要填写的限制
            //        var pages = $(".page");
            //        $.each(pages, function(key, value) {
            //            var txtBox = $(value).children(".txtInput");
            //            txtBox.each(function() {
            //                if ($(this).val() == "") {
            //                    flag = false;
            //                    msg = "表单存在未填写项";
            //                }
            //            });
            //        })

            if (!flag)
                alert(msg);
            else {
                var table = prodTable();
                $('#sqlargs').val(table);
                //show_cover();
            }
            return flag;
        }

        // 遍历table获得每个单元格的值
        function prodTable() {
            var tableDiv = $("#updateTable");
            var tbody = $(tableDiv).children().children();
            var trs = $(tbody).children('tr');
            var trCount = trs.length;
            var rows = "";
            var row;
            trs.each(function() {
                row = '';
                $(this).children().each(function() {
                    var hidTag = $(this).children('.tbvalget');
                    var hidcls = $(hidTag).attr('class');
                    if (hidcls != "undefined" && hidcls != "" && hidcls != null && hidcls != "null") {
                        //alert($(hidTag).val());
                        row += $(hidTag).val() + ',';
                    }
                });
                rows += row + ';';
            })
            return rows;
        }
   
    </script>

    <script type="text/javascript">
        //初始化文件选择树
        function wfstart_intityFileTree() {
            $.ajax({
                url: "/Home/getFileTree",
                type: "POST",
                data: { type: "person" },
                success: function(fileNodes) {
                    setting.callback.onClick = wfstart_onFiletreeClick;
                    var treeObj = $.fn.zTree.init($("#treeDemo"), setting, eval(fileNodes));
                    $("#treeDemo").show();
                    var wfappendix = $("#wfappendix").val();
                    if (wfappendix != "") {//如果不是空，说明是第二次点击附件按钮，自动把上次选中的文件节点勾选
                        var node = treeObj.getNodesByParam("id", wfappendix, null);
                        treeObj.checkNode(node, true);
                    }
                }
            })
        }

        function wfstart_onFiletreeClick(event, treeId, treeNode) {
            // alert(treeNode.tId + ", " + treeNode.name + " , " + treeNode.id + " , " + treeNode.tag);
            if (treeNode.name.replace(/.+\./, "") == "rar") {
                var treeObj = $.fn.zTree.getZTreeObj("treeDemo");
                $("#txt_appendix").attr("value", treeNode.name);
                $("#wfappendix").attr("value", treeNode.tag);
                //$("#treeDemo").hide();
            }
            else
                alert("请选择rar作为附件");

        };

        function ClearAppendix() {
            $("#txt_appendix").attr("value", "");
            $("#wfappendix").attr("value", "");
        }

        function proRes(ajaxContext) {
            var restag = {};
            try {
                restag = ajaxContext.get_response().get_object();
            } catch (e) {
                alert("程序出现错误，请联系管理员");
                return;  // return if result is not json
            }
            if (restag.res != true) {
                alert(restag.msg);
            }
            else {
                alert("操作成功");

            }
            //hide_cover();
        }

        init_bd();
        function init_bd() {
            var page = $("#div_bd_main").children("div").children("#div_bd").children(".page");
            var trans = $(page).children("#EmployeeTransOfficial");
            if ($(trans).html() != "null") {
                var name = $(page).children("#name");
                $(name).unbind("blur");
                $(name).bind("blur", function() { fill_usr_info(this); });
            }
        }

        function fill_usr_info(tag) {
            var name = $(tag).val();
            var page = $("#div_bd_main").children("div").children("#div_bd").children(".page");
            $.getJSON(
            "/TmpUsr/QueryUser",
            { name: name },
            function(jsonData) {
                if (jsonData.name != "") {
                    $(page).children("#dept").val(jsonData.dept);
                    $(page).children("#duty").val(jsonData.duty);
                    $(page).children("#gender").val(jsonData.gender);
                    $(page).children("#birthday").val(jsonData.birthday);
                    $(page).children("#height").val(jsonData.height);
                    $(page).children("#race").val(jsonData.race);
                    $(page).children("#politics").val(jsonData.politics);
                    $(page).children("#marrige").val(jsonData.marrige);
                    $(page).children("#schooling").val(jsonData.schooling);
                    $(page).children("#major").val(jsonData.major);
                    $(page).children("#identityCard").val(jsonData.identityCard);
                    $(page).children("#phone").val(jsonData.phone);
                    $(page).children("#revealed").val(jsonData.revealed);
                    $(page).children("#address").val(jsonData.address);
                    $(page).children("#timeIn").val(jsonData.timeIn);
                    $(page).children("#salaryTry").val(jsonData.salaryTry);
                    $(page).children("#salaryOfficial").val(jsonData.salaryOfficial);
                }
            }
        );
        }

        function get_tmp_usr() {
            var main_form = $("#div_bd_main");
            var elemTrans = $(main_form).children("div").children("#div_bd").children(".page").children("#EmployeeTransOfficial").html();
            var result = "";
            result += $("#name").val() + ",";
            result += $("#dept").val() + ",";
            result += $("#duty").val() + ",";
            result += $("#gender").val() + ",";
            result += $("#birthday").val() + ",";
            result += $("#height").val() + ",";
            result += $("#race").val() + ",";
            result += $("#politics").val() + ",";
            result += $("#marrige").val() + ",";
            result += $("#schooling").val() + ",";
            result += $("#major").val() + ",";
            result += $("#identityCard").val() + ",";
            result += $("#phone").val() + ",";
            result += $("#revealed").val() + ",";
            result += $("#address").val() + ",";
            result += $("#timeIn").val() + ",";
            result += $("#salaryTry").val() + ",";
            result += $("#salaryOfficial").val() + "";
            $.ajax({
                type: "POST",
                url: "/TmpUsr/AddUser",
                data: { "tmpuser": result }
            })
        }
    </script>

</head>
<body>
    <div>
        <div id="wfstart" style="padding-top: 35px;">
            <div id="menus">
                <%using (Ajax.BeginForm("DoWFStart", "WorkFlow", new AjaxOptions { UpdateTargetId = "temp", OnSuccess = "proRes" }))
                  { %>
                <br />
                <div id="div_bd_main">
                    <div style="width: 650px; float: left; margin-left: 10px; background-color: #F9F9F9;
                        border: solid 1px #6C92AD;">
                        <div id="div_bd" style="position: relative; height: 800px; width: 600px; margin-left: 13px;
                            overflow: auto; padding: 5px;">
                            <% Response.Write(ViewData["formdefi"]); %>
                        </div>
                        <div class="div_hide">
                            <%=Html.Hidden("user_id", ViewData["user_id"])%>
                            <%=Html.Hidden("form_id", ViewData["form_id"])%>
                            <%=Html.Hidden("wftemplate_id", ViewData["wftemplate_id"])%>
                            <%=Html.Hidden("wf_id", ViewData["wf_id"])%>
                            <%=Html.Hidden("selectarr", ViewData["clrs"])%>
                            <%=Html.Hidden("treedefi", ViewData["treedefi"])%>
                            <%=Html.Hidden("treevis", ViewData["treevisible"])%>
                            <%=Html.Hidden("sqlargs")%>
                        </div>
                    </div>
                    <%-- <div style="float: left; height: 800px; width: 310px; margin-left: 40px;">
                        <div style="width: 300px; height: 500px; float: left; position: fixed; top: 130px;
                            left: 950px;">
                            <div id="div_bd_tail" style="width: 300px; height: 60px; float: left;">
                                <div style="width: 100%; display: none;">
                                    <div style="width: 35%;">
                                        审批建议：
                                    </div>
                                    <div style="width: 75%;">
                                        <%=Html.TextArea("ins_descn", "无",new { style = "width:250px;border:solid 1px #6C92AD;" })%>
                                    </div>
                                </div>
                                <div style="width: 100%;">
                                    <div style="width: 18%; float: left;">
                                        附件名：
                                    </div>
                                    <div style="width: 80%; float: left;">
                                        <input type="text" id="txt_appendix" style="width: 207px; border: solid 1px #6C92AD;" /><%=Html.Hidden("wfappendix")%>
                                    </div>
                                </div>
                                <br />
                                <div style="width: 100%;">
                                    <div style="width: 33%; float: left;">
                                        <input class="btn_style" type="button" value="上传文件" onclick="wfstart_intityFileTree()" /></div>
                                    <div style="width: 50%; float: left;">
                                        <input class="btn_style" type="button" value="清空附件" onclick="ClearAppendix()" /></div>
                                </div>
                            </div>
                            <div id="div_tree" class="zTreeDemoBackground left" style="float: left; height: 240px;">
                                <ul id="treeDemo" class="ztree" style="height: 230px; width: 260px; float: left;">
                                </ul>
                            </div>
                        </div>
                    </div>--%>
                </div>
            </div>
            <div style="float: left; width: 100%; margin-top: 30px;">
                <input class="btn_style" type="submit" value="完成并发送" onclick="return OnSubmit()" />
                <%} %>
            </div>
        </div>
    </div>
</body>
</html>
